package top.xinsix.est.controller;

import top.xinsix.est.constants.Constants;
import top.xinsix.est.dto.ModelDto;
import top.xinsix.est.dto.Page;
import top.xinsix.est.req.ModelReq;
import top.xinsix.est.service.ModelService;
import top.xinsix.est.tools.Result;
import top.xinsix.est.tools.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商品的型号
 */
@RestController
@RequestMapping("/api/model")
public class ModelController {
    @Autowired
    private ModelService modelService;
    @GetMapping("/search")
    public Result search(ModelReq modelReq){
        if(modelReq.getPageNo()==null){
            modelReq.setPageNo(Constants.DEFAULT_PAGE_NO);
        }
        if(modelReq.getPageSize()==null){
            modelReq.setPageSize(Constants.DEFAULT_PAGE_SIZE);
        }
        Page page=modelService.search(modelReq);
        return ResultUtils.returnDataSuccess(page);
    }
    @GetMapping("{id}/detail")
    public Result detail(@PathVariable Long id){
        ModelDto modelDto = modelService.getModelDtoById(id);
        return ResultUtils.returnDataSuccess(modelDto);
    }
}
